/**
 * Trang menu chinh cua game
 */
package view;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import model.Constant;
import model.database.ConnectDB;

/**
 * @author heroandtn3
 *
 */
public class HomePanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static final String KEY = "HomePanel";
	private MainPanel mainPanel;
	private JLabel lbSetting;
	private JLabel lbAbout;
	private JLabel lbExit;
	private JLabel lbHelp;
	private JLabel lbSlide;
	private JLabel lbTitle;
	private JLabel lbHighScore;
	private JLabel lbPlay;

	/**
	 * 
	 */
	public HomePanel(MainPanel mainPanel) {
		// TODO Auto-generated constructor stub
		this.mainPanel = mainPanel;
		initGUI();
		
	}
	
	
	private void initGUI() {
		try {
			{
				this.setLayout(null);
				this.setPreferredSize(new java.awt.Dimension(900, 680));
				this.setBackground(new java.awt.Color(0,138,0));
				{
					lbPlay = new MyLabelButton(Constant.BUTTON_DIR + "play.png", "Play a game", true);
					this.add(lbPlay);
					lbPlay.setBounds(460, 20, 200, 200);
					lbPlay.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							//TODO add your code for lbPlay.mouseClicked
							if (ConnectDB.connect()) {
								mainPanel.switchPanel(LoginPanel.KEY);
							} else {
								mainPanel.switchPanel(ConfigPanel.KEY);
							}
							
						}
					});
				}
				{
					lbHighScore = new MyLabelButton(Constant.BUTTON_DIR + "highscore.png", "High Score", true);
					this.add(lbHighScore);
					lbHighScore.setBounds(460, 240, 200, 200);
					lbHighScore.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							//TODO add your code for lbHighScore.mouseClicked
							if (ConnectDB.connect()) {
								mainPanel.switchPanel(HighScorePanel.KEY);
								mainPanel.getHighScorePanel().initHighScore();
							} else {
								mainPanel.switchPanel(ConfigPanel.KEY);
							}
						}
					});
				}
				{
					lbSetting = new MyLabelButton(Constant.BUTTON_DIR + "settings.png", "Settings", true);
					this.add(lbSetting);
					lbSetting.setBounds(460, 460, 200, 200);
					lbSetting.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							//TODO add your code for lbSetting.mouseClicked
							mainPanel.switchPanel(ConfigPanel.KEY);
						}
					});
				}
				{
					lbAbout = new MyLabelButton(Constant.BUTTON_DIR + "about.png", "About us", true);
					this.add(lbAbout);
					lbAbout.setBounds(680, 20, 200, 200);
					lbAbout.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							//TODO add your code for lbAbout.mouseClicked
							mainPanel.switchPanel(AboutPanel.KEY);
						}
					});
				}
				{
					lbHelp = new MyLabelButton(Constant.BUTTON_DIR + "help.png", "Help", true);
					this.add(lbHelp);
					lbHelp.setBounds(680, 240, 200, 200);
					lbHelp.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							//TODO add your code for lbHelp.mouseClicked
							mainPanel.switchPanel(HelpPanel.KEY);
						}
					});
				}
				{
					lbExit = new MyLabelButton(Constant.BUTTON_DIR + "exit.png", "Exit game", true);
					this.add(lbExit);
					lbExit.setBounds(680, 460, 200, 200);
					lbExit.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							//TODO add your code for lbExit.mouseClicked
							System.exit(0);
						}
					});
				}
				{
					lbSlide = new JLabel(new ImageIcon(Constant.BG_DIR + "home.png"));
					this.add(lbSlide);
					lbSlide.setBounds(20, 198, 440, 472);
				}
				{
					lbTitle = new JLabel(new ImageIcon(Constant.BG_DIR + "title.png"));
					this.add(lbTitle);
					lbTitle.setBounds(109, 59, 310, 105);
				}
			}
		} catch(Exception e) {
			//e.printStackTrace();
		}
	}

}
